<?php
/**
 * @Author: Marte
 * @Date:   2017-08-10 20:28:20
 * @Last Modified by:   Marte
 * @Last Modified time: 2017-08-22 21:33:45
 */
session_start();
header('Content-Type:text/html;charset=utf-8');
include "data/config_connect.php";//导入数据库

if(isset($_GET['id']))
{
    $_id=$_GET['id'];
    $sql='select * from books where bookid='."$_id".'';
    $_result=$_mysql->query($sql);
    $_assoc=$_result->fetch_assoc();

}
if(isset($_GET['name'])&&isset($_GET['add'])&&$_GET['add']==1)
{
    $_username=$_GET['name'];
     $_id=$_GET['id'];
    $_bookname=$_assoc['bookname'];
    $_bookid=$_assoc['bookid'];
    $_picpath=$_assoc['picpath'];
    //首先查询是否已经储存有该条收藏记录，如果有，则不添加了就
    $_sql0='select username,bookname from  bookshelf';
    $_result=$_mysql->query($_sql0);

    while($_assoc0=$_result->fetch_assoc())
    {
        if($_assoc0['username']==$_username&&$_assoc0['bookname']==$_bookname)
        {
            // 如果即有相同的用户名，也有相同的收录书目，则就不执行该操作了

            echo "<script>location='bookinfo.php?action=xx&id=".$_id." ;</script>";
            echo "<script>alert('您已经加入书架了哦！');</script>";


        }
        else
        {
            // 如果这本书之前没有被该用户收录过，就继续执行收录
            $sqll="INSERT INTO bookshelf (username,bookid,bookname,picicon,time) VALUES ('$_username', '$_bookid', '$_bookname','$_picpath',now())";
                if($_mysql->query($sqll))
                {
                    echo"<script>location='bookinfo.php?action=xx&id=".$_id."&success=1';</script>";
                    echo "<script>alert('加入成功！');</script>";
                    break;

                }
                else
                {
                    echo "fail".$_mysql->error;
                }
        }
    }


}
$bookid=$_GET['id'];
require 'common/change_num.func.php';
$_sql3='select * from book_section where bookid="'.$bookid.'" order by secnum desc';
$_result3=$_mysql->query($_sql3);
$assoc3=$_result3->fetch_assoc();
// 统计评论数

$sql7="select id from book_comment where bookid='$bookid'";

$_result4=$_mysql->query($sql7);
$num=mysqli_affected_rows($_mysql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title><?php echo $_assoc['bookname'] ?></title>
    <link rel="shortcut icon" href="title.ico" />
<link rel="stylesheet" type="text/css" href="css/base.css" />
<!-- main.css | 页面主体样式 -->
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="plug_ins/popup/popup.css">
<!-- js -->
<script type="text/javascript" src="js/jquery-1.8.3.min.js" /></script>
<script src="js/jquery.min.js" type="text/javascript" ></script>
<script type="text/javascript" src="js/jquery.SuperSlide.2.1.1.js" /></script>
<script type="text/javascript" src="js/bookinfo.js"></script>
<script src="js/send_comment.js"></script>
<script src="plug_ins/popup/common.js" type="text/javascript" charset="utf-8" ></script>
</head>
<body>

<div class="header_full w_100">
    <div class="header">
        <!-- top_left | logo -->
        <div class="logo f_l"><img src="images/logo22.png" width="210" height="42" /></div>
        <!-- top_right -->
        <div class="top_right f_r">
            <!-- top_link -->

            <!-- menu -->
            <div class="nav_bar">
                <ul class="nav clearfix">

                    <!-- 单一菜单 | end -->

                    <li class="m">
                        <h3><a target="_blank" href="mybookrack.php" title="合作专区">朕的书架</a></h3>

                    </li>
                    <li class="s">|</li>

                    <li class="m">
                        <h3><a target="_blank" href="person.php" title="客户服务">个人中心</a></h3>

                    </li>
                    <li class="s">|</li>

                    <li class="m">
                        <h3><a target="_blank" href="index.php" title="大头网">墨轩首页</a></h3>

                    </li>
                    <li class="s">|</li>

                    <li class="m">
                        <h3><a target="_blank" href="allbooks.php" title="产品服务">墨轩书城</a></h3>

                    </li>
                    <li class="s">|</li>

                    <li class="m">
                        <h3><a href="#" title="首页">书目主页</a></h3>
                    </li>
                    <li class="block"></li><!-- 滑动块 -->
                </ul>
            </div>
            <!-- menu | end -->
        </div>
    </div>
</div>
<div class="bg">

</div>
<div class="bookinfo">
    <i><a href="read_page.php?bookid=<?php echo $_assoc['bookid'];?>" title=""><img src="<?php echo $_assoc['picpath'];?>" alt=""></a></i>
    <div class="right">
        <span class="title1"><?php echo $_assoc['bookname'];?></span><span class="author"><?php echo $_assoc['bookauthor'];?></span>
        <div class="sort1">
            <span class="sort">
                <?php
                    $_i=$_assoc['isend'];
                    switch($_i)
                    {
                        case 1:echo "完结";break;
                        case 0:echo "连载中";break;

                    }
                ?>
            </span><span class="sort">签约</span><span class="sort">
                <?php
                    $_v=$_assoc['isvip'];
                    switch($_i)
                    {
                        case 1:echo "VIP";break;
                        case 0:echo "免费";break;
                    }
                ?>
            </span><span class="sort sort2">
                <?php
                    $_p=$_assoc['typeid'];
                    switch($_p)
                    {
                                    case 1:echo "玄幻" ;break;
                                    case 2:echo "奇幻";break;
                                    case 3:echo "武侠";break;
                                    case 4:echo "仙侠";break;
                                    case 5:echo "都市";break;
                                    case 6:echo "现实";break;
                                    case 7:echo "历史";break;
                                    case 8:echo "军事";break;
                                    case 9:echo "校园";break;
                                    case 10:echo "游戏";break;
                                    case 11:echo "言情";break;
                                    case 12:echo "灵异";break;
                                    case 13:echo "N次元";break;
                    }
                ?>
            </span><span class="sort sort2"><?php echo $_assoc['lable'];?></span>
        </div>
        <p><?php echo $_assoc['descripation'];?></p>
        <div class="bottom">
            <span class="look"><em><?php echo $_assoc['words'];?></em>万字|</span><span class="look"><em><?php echo $_assoc['allhits'];?></em>总点击|</span><span class="look"><em>73.58</em>万总推荐</span>
        </div>
        <div class="user">
            <span class="active"><a href="read_page.php?bookid=<?php echo $_assoc['bookid'] ?>" title="">立即阅读</a></span>
            <?php
                // if(isset($_SESSION['username'])&&(!isset($_GET['success'])))
                // {
                //     echo '<span><a href="bookinfo.php?action=xx&id='.$_assoc['bookid'].'&name='.$_SESSION['username'].'&add=1" title="">加入书架</a></span>';
                // }
                // else if(!(isset($_SESSION['username'])))
                // {
                //     echo '<span><a href="dl.php" title="">加入书架</a></span>';
                // }else if(isset($_GET['success'])&&$_GET['success']==1)
                // {
                //     echo '<span><a href="mybookrack.php" title="">已在书架</a></span>';
                // }
                if (isset($_SESSION['username'])) {
                    $_ssqqll='select id from bookshelf where bookname="'.$_assoc['bookname'].'" and username="'.$_SESSION['username'].'" ';
                $result=$_mysql->query($_ssqqll);
                if($_assocs=$result->fetch_assoc())
                {
                     echo '<span><a href="mybookrack.php" title="">已在书架</a></span>';
                }
                else
                {
                    echo '<span><a href="bookinfo.php?action=xx&id='.$_assoc['bookid'].'&name='.$_SESSION['username'].'&add=1" title="">加入书架</a></span>';
                }
                }else
                {
                     echo '<span><a href="dl.php" title="">加入书架</a></span>';
                }

            ?>

            <span><a href="" title="">加入收藏</a></span>
        </div>
    </div>
    <div class="right_right">
        <span class="first"><?php echo $_assoc['grade'];?></span>
        <span class="pipin"><?php echo $_assoc['givegrade_num'];?>人评价</span>
        <span class="pinjia">我要评价</span>
        <span class="xiazai"><a href="" title="">下载</a></span>
    </div>
</div>
<div class="nav1">

        <a class="ok" href="bookinfo.php?action=xx&id=<?php echo $_id;?>" title="">作品信息</a>
        <a href="bookinfo.php?action=ml&id=<?php echo $_id;?>" title="">目录</a>
        <a href="bookinfo.php?action=pl&id=<?php echo $_id;?>" title="">作品讨论(<?php echo $num;?>条)</a>


</div>
    <?php
      if(isset($_GET['action']))
        {
                switch($_GET['action'])
            {
                case 'xx': include 'include/bookinfo_js.inc.php';break;
                case 'ml': include 'include/bookinfo_ml.inc.php';break;
                case 'pl':include 'include/bookinfo_pl.inc.php';break;
            }
        }else{
            require 'include/bookinfo_js.inc.php';
        }

    ?>
    <script>
        $(function(){
    var win=$(".win");
    var links=$(".title a");
    var float=$(".float");
    var divs=$(".box div");
    var num1=0;  //
    var num2=0;
    win.hover(function(){
        $(".leftB,.rightB").css("display","block");
    },function(){
        $(".leftB,.rightB").css("display","none");
    });
    $(".leftB").click(function(){
        divs.finish();
        float.stop(true);
        var temp=num1;
        num1--;
        if(num1==-1){
            num1=4;
        }
        divs.eq(num1).css("left",220).animate({left:0});
        divs.eq(temp).animate({left:-220});
        links.css("color","#009797");
        float.animate({left:links.eq(num1).position().left})
        links.eq(num1).css("color","#fff");
    });
    $(".rightB").click(function(){
        divs.finish();
        float.stop(true);
        var temp=num1;
        num1++;
        if(num1==5){
            num1=0;
        }
        divs.eq(num1).css("left",-220).animate({left:0});
        divs.eq(temp).animate({left:20});
        links.css("color","#009797");
        float.animate({left:links.eq(num1).position().left})
        links.eq(num1).css("color","#fff");
    });
    links.hover(function(){
        //
        divs.finish();
        float.stop(true);
        links.css("color","#009797");
        var that=$(this);
        var lefts=$(this).position().left;
        float.animate({left:lefts},function(){
            that.css("color","#fff");
        })
        //
        //
        var index=$(this).index(".title a");
        num2=index;
        if(num1==num2){
            return;
        }else if(num1<num2){
            divs.eq(num2).css("left",220).animate({left:0});
            divs.eq(num1).animate({left:-220});
        }else if(num1>num2){
            divs.eq(num2).css("left",-220).animate({left:0});
            divs.eq(num1).animate({left:220});
        }
        num1=num2;
        num2="";
    },function(){

    })
})
    </script>
</body>
</html>

